package cn.webestar.scms.user.api.dto.SysDict;

import cn.webestar.scms.commons.api.SimpleBody;
import cn.webestar.scms.user.entity.SysDict;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.util.StringUtils;

@Data
@Schema(description = "SysDictSimpleDTO")
public class SysDictSimpleDTO extends SimpleBody {

    @Schema(description = "父键")
    private String pcode;

    @Schema(description = "键")
    private String code;

    @Schema(description = "值")
    private String val;

    @Schema(description = "名称")
    private String name;

    @Schema(description = "排序")
    private Integer sort;

    @Override
    public LambdaQueryWrapper<SysDict> toQueryWapper() {
        LambdaQueryWrapper<SysDict> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(pcode)) {
            queryWrapper.eq(SysDict::getPcode, pcode);
        }
        if (StringUtils.hasText(code)) {
            queryWrapper.eq(SysDict::getCode, code);
        }
        if (StringUtils.hasText(val)) {
            queryWrapper.eq(SysDict::getVal, val);
        }
        if (StringUtils.hasText(name)) {
            queryWrapper.eq(SysDict::getName, name);
        }
        if (sort!=null) {
            queryWrapper.eq(SysDict::getSort, sort);
        }
        return queryWrapper;
    }

}
